package com.qing.springcloud.service;

import com.qing.springcloud.entity.Order;
import com.qing.springcloud.feignService.StockFeignService;
import com.qing.springcloud.mapper.OrderMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService{


    @Autowired
    private OrderMapper orderMapper;


    @Autowired
    private StockFeignService stockFeignService;
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public String createOrder(String userId, String productId, int num) {
//        创建订单
        Order order=new Order(userId,productId,num);
        orderMapper.createOrder(order);
        int a=10/0;
        //        减少库存
        stockFeignService.reduce(1,num);
        return "订单创建成功！";
    }
}
